package com.atguigu.srb.core.controller.admin;


import com.atguigu.common.result.R;
import com.atguigu.srb.core.pojo.entity.UserInfo;
import com.atguigu.srb.core.pojo.query.UserInfoQuery;
import com.atguigu.srb.core.service.UserInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户基本信息 前端控制器
 * </p>
 *
 * @author tjf
 * @since 2022-01-03
 */
@Api(tags = "会员管理")
@RestController
//@CrossOrigin
@Slf4j
@RequestMapping("/admin/core/userInfo")
public class AdminUserInfoController {

    private final UserInfoService userInfoService;

    public AdminUserInfoController(UserInfoService userInfoService) {
        this.userInfoService = userInfoService;
    }

    @ApiOperation("获取会员分页列表")
    @GetMapping("/list/{page}/{limit}")
    public R listPage(@ApiParam(value = "查询条件", required = false) UserInfoQuery userInfoQuery,
                      @ApiParam("当前页码") @PathVariable Long page,
                      @ApiParam("每页记录数") @PathVariable Long limit) {
//        LambdaQueryWrapper<UserInfo> queryWrapper = new LambdaQueryWrapper<>();
//        if (!StringUtils.isBlank(userInfoQuery.getMobile())) {
//            if (userInfoQuery.getMobile() != null) {
//                queryWrapper.eq(UserInfo::getMobile, userInfoQuery);
//            }
//            if (userInfoQuery.getStatus() != null) {
//                queryWrapper.eq(UserInfo::getUserType, userInfoQuery.getUserType());
//            }
//            if (userInfoQuery.getStatus() != null) {
//                queryWrapper.eq(UserInfo::getUserType, userInfoQuery.getUserType());
//            }
//        }
//        Page<UserInfo> pageModel = userInfoService.page(Page.of(page, limit), queryWrapper);
        Page<UserInfo> pageModel = userInfoService.pageList(page, limit, userInfoQuery);
        return R.ok().message("获取用户信息成功").data("pageModel", pageModel);
    }

    @ApiOperation("锁定或解锁用户")
    @PutMapping("/lock/{id}/{status}")
    public R lock(@ApiParam("用户id") @PathVariable Long id,
                  @ApiParam("锁定状态") @PathVariable Integer status) {
        userInfoService.lock(id, status);
        return R.ok().message(status == 1 ? "解锁成功": "锁定成功");
    }
}

